<template>
    <el-row>
        <el-col class="btn">
            <el-dialog :visible.sync="dialogVisible" width="625px" :before-close="handleClose" @close="handleClose()">
                <div slot="title" class="dialog-title box box-align-center">
                    <i class="title-icon"></i>
                    <span class="title-text ml10">{{title}}</span>
                </div>
                <el-form ref="form" :model="form" label-width="80px" class="reset-form">
                    <el-input @input="listNotInJyzUser(page.pageNum)" class="reset-input w100" placeholder="搜索教师姓名或教职工号" v-model="form.searchText" @input.native="listNotInJyzUser()">
                        <i slot="suffix" class="el-input__icon el-icon-search cp" @click="listNotInJyzUser()"></i>
                    </el-input>
                </el-form>
                <div class="user-list radio">
                    <el-col class="box box-pack-center ml30">
                        <div class="list box box-align-center">
                            <span class="item">姓名</span>
                            <span class="item">教职工号</span>
                            <span class="item">手机号</span>
                        </div>
                    </el-col>
                    <el-checkbox-group v-model="checkedTrs" @change="handleCheckedChange" v-if="page.list.length != 0">
                        <el-checkbox v-for="(item,index) in page.list" :label="item.id" :key="index">
                            <div class="list box box-align-center">
                                <span class="item">{{item.name}}</span>
                                <span class="item">{{item.zgh}}</span>
                                <span class="item">{{item.mobile}}</span>
                            </div>
                        </el-checkbox>
                    </el-checkbox-group>
                    <el-col v-else>
                        暂无数据
                    </el-col>

					<el-col class="mt20 mb20 change">
						<el-pagination @current-change="listNotInJyzUser" background layout="prev, pager, next" :total="page.total"
						    :current-page="page.pageNum" :page-size="page.pageSize" hide-on-single-page></el-pagination>
					</el-col>

                </div>
                <span slot="footer" class="dialog-footer">
                    <el-button class="reset-cancel-btn" @click="handleClose()">取 消</el-button>
                    <el-button class="reset-comfirm-btn" @click="onSubmit()">保 存</el-button>
                </span>
            </el-dialog>
        </el-col>
    </el-row>
</template>

<script>
    export default {
        props: {
            dialogVisible: {
                default: false
            },
            title: {
                default: '添加成员'
            },
            info: {

            },
            jyzid:{
                type:Number
            }
        },
        data() {
            return {
                form: {
                    searchText: '',
                    radio: ''
                },
                checkedTrs: [],
                isIndeterminate: true,
                page: {
                    total: 0,
                    pageSize: 10,
                    pageNum: 1,
                    list: []
                },
                schoolid:this.$store.state.schoolId,
            };
        },
        mounted(){
          console.log(this.dialogVisible)
        },
        methods: {
            listNotInJyzUser(pageNum){
                this.$api.jyz.listNotInJyzUser({
                    'schoolid': this.schoolid,
                    'searchtext': this.form.searchText,
                    'pageNum':pageNum
                }).then(res => {
                    if (res.code == '0') {
                        this.page = res.list;
                    } else {
                        this.$message.error('请求失败！');
                    }
                })
            },
            handleClose() {
                this.$emit('clickClose')
            },
            onSubmit() {
                this.$api.jyz.addJyzUser({
                    'ids': this.checkedTrs.join(","),
                    'jyzid': this.jyzid
                }).then(res => {
                    if (res.code == '0') {
                        this.$message.success('操作成功！');
                        this.$emit('xtjyUserList');
                        this.$emit('clickClose');
                    } else {
                        this.$message.error('请求失败！');
                    }
                })
            },
            handleCheckedChange(value) {
                let checkedCount = value.length;
                this.isIndeterminate = checkedCount > 0 && checkedCount < this.page.list.length;
            }
        }
    };
</script>

<style scoped lang="scss">
    .upload-icon {
        width: 110px;
        height: 110px;
        background-color: #F0F1F8;
        line-height: 110px;
        color: #626BF1;
        font-size: 30px;
        border-radius: 10px;
    }

    .avatar {
        width: 110px;
        height: 110px;
    }

    .w100 {
        width: 100%;
    }

    .reset-form {
        padding: 0 20px;
    }


    .user-list {

        .checkbox__label {
            width: 80%;
        }

        .list {
            padding: 10px 0;
        }

        .item {
            display: block;
            width: 120px;
            margin-right: 30px;
        }
    }

    .user-list>>>.el-checkbox {
        padding: 0 20px;
        width: 585px;
        margin-right: 0;
        display: flex;
        justify-content: center;
    }

    .user-list>>>.el-checkbox__label {
        .list {
            display: flex;
            color: #000000;
        }
    }

    .user-list>>>.el-checkbox__input {
        display: flex;
        align-items: center;
    }

    .user-list>>>.el-checkbox__input.is-checked .el-checkbox__inner {
        background-color: #626BF1;
        border-color: #626BF1;
    }

    .user-list>>>.el-checkbox__inner:hover {
        border-color: #626BF1;
    }

    .user-list>>>.el-checkbox__input.is-focus,
        {
        border-color: #626BF1;

        .el-checkbox__inner {
            border-color: #626BF1;
        }
    }
	.change>>>{}
</style>
